package com.masterclient.app.businessmodule.vipmodule.financial_management.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.masterclient.app.R;
import com.masterclient.app.businessmodule.vipmodule.financial_management.bean.BankCardBean;

public class BankListAdapter extends BaseQuickAdapter<BankCardBean, BaseViewHolder> {

    private String bankCardId = "";
    private String fromPageType = "";

    public String getBankCardId() {
        return bankCardId;
    }

    public void setBankCardId(String bankCardId) {
        this.bankCardId = bankCardId;
        notifyDataSetChanged();
    }

    public BankListAdapter(String fromPageType) {
        super(R.layout.item_bank_list);
        this.fromPageType = fromPageType;
    }

    @Override
    protected void convert(BaseViewHolder helper, BankCardBean item) {
        ImageView bankLogo = helper.getView(R.id.item_bank_logo);
        TextView bankName = helper.getView(R.id.item_bank_name);
        ImageView bankSelected = helper.getView(R.id.item_bank_selected);
        TextView bankNo = helper.getView(R.id.item_bank_no);

        if (!"setting".equals(fromPageType)) {
            if (helper.getAdapterPosition() == getData().size() - 1) {
                bankLogo.setImageResource(R.drawable.flower_add_bank);
                bankName.setText("添加新的银行卡");
                bankNo.setVisibility(View.GONE);
                bankSelected.setImageResource(R.drawable.flower_arrow_right_black);
            } else {
                ViewTransformUtil.glideImageView(mContext, item.cardBg, bankLogo, R.drawable.flower_placeholder);
                bankName.setText(item.bankShort);
                bankNo.setText(item.card);
                bankNo.setVisibility(View.VISIBLE);
                bankSelected.setImageResource(bankCardId.equals(item.bankcardCertId) ? R.drawable.flower_radio_oval_selected : R.color.transparent);
            }
        }else {
            ViewTransformUtil.glideImageView(mContext, item.cardBg, bankLogo, R.drawable.flower_placeholder);
            bankName.setText(item.bankShort);
            bankNo.setText(item.card);
            bankNo.setVisibility(View.VISIBLE);
            bankSelected.setVisibility(View.GONE);
        }
    }
}
